package com.yoki.loginview.db;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class AccountDBHelper2 extends SQLiteOpenHelper {
    private Context mContext;
    static final String DB_Name = "user.db";
    static final String TABLE_Name = "tb_accounts";
    public static final int VERSION_1 = 1;
    private final String sql_create_table = "create table tb_accounts (id integer primary key autoincrement, user text unique, password text, email text, admin integer)";

    public AccountDBHelper2(Context mContext, int version) {
        super(mContext, DB_Name, null, version);
        this.mContext = mContext;
    }

    public Cursor select(String where, String orderby)//根据传入的参数合成SQL查询语句
    {
        StringBuilder stringBuilder = new StringBuilder("SELECT * FROM "+TABLE_Name);//附加上WHERE和ORDER By信息
        if (where != null)
        {
            stringBuilder.append(" WHERE ");
            stringBuilder.append(where);
        }
        if (orderby != null)
        {
            stringBuilder.append(" ORDER BY ");
            stringBuilder.append(orderby);
        }
        Log.d("DB",stringBuilder.toString());
        //返回查询结果的Cursor对象
         return getWritableDatabase().rawQuery(stringBuilder.toString(),null);
    }


    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(sql_create_table);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }
}










